<tagLib name="fanwe" />
<include file="Public:header" />
<php>
	function getUrlShow($url)
	{
		return "<a href='".$url."' target='_blank'>".$url."</a>";
	}
</php>
<script type="text/javascript" src="__TMPL__Static/Js/dataList.js"></script>
<div class="handle-btns">
	<fanwe:imageBtn id="editData" name="editData" value="{$Think.lang.EDIT}" click="editData(this,'checkList')" />
	<fanwe:imageBtn id="removeData" name="removeData" value="{$Think.lang.REMOVE}" click="removeData(this,'checkList')" />
	<fanwe:imageBtn id="disableShop" name="disableShop" value="{$Think.lang.DISABLE}" click="disableShop(this,'checkList')" />
	<fanwe:imageBtn id="checkShop" name="checkShop" value="{$Think.lang.CHECK_SELECT}" click="checkShop(this,'checkList')" />
</div>
<fanwe:list 
	id="checkList" 
	style="list" 
	name="shop" 
	pk="shop_id" 
	checkbox="true" 
	action="true" 
	datasource="list" 
	show="shop_id:{$Think.lang.ID}|80,shop_logo|getTooltipImg:{$Think.lang.IMG_ID}|50,shop_name:{$Think.lang.SHOP_NAME}|300~left,shop_url|getUrlShow:{$Think.lang.SHOP_URL}|~left" 
	actionlist="checkShop:{$Think.lang.CHECK}:shop_id,disableShop:{$Think.lang.DISABLE}:shop_id,removeData:{$Think.lang.REMOVE}:shop_id" action_width="160" />
<div class="pager">{$page}</div>
<script type="text/javascript">
function checkShop(obj,id,pk,args)
{
	var ids =  new Array();
	if(isNaN(id))
	{
		$("#" + id + " input:checked[name='key']").each(function(){
			ids.push(this.value);
		});
	}
	else
	{
		ids.push(id);
		var parent = $(obj).parent().parent();
		id = parent.parent().parent().attr('id');
	}
	
	ids = ids.join(',');
	if(ids == '')
		return false;
	
	var query = new Object();
	query.id = ids;
	
	$.ajax({
		url: APP + '?' + VAR_MODULE + '=' + CURR_MODULE + '&' + VAR_ACTION + '=checkOk',
		type:"POST",
		cache: false,
		data:query,
		dataType:"json",
		success: function(result){
			if(result.isErr == 0)
			{
				var fun = function(parent){
					$('td span,td a',parent).each(function(){
						if (typeof(this.onclick) == 'function' && this.onclick.toString() != '')
						{
							if(this.onclick.toString().indexOf('toggleStatus') != -1)
							{
								var img = $('img',this).get(0);
								img.src = img.src.replace('status','disabled');
							}
							
							this.onclick = '';
						}
					});
					
					parent.attr({"disabled":true,"title":ALREADY_REMOVE});
					$("td",parent).attr({"disabled":true}).addClass('disabled');
					$("td *",parent).attr({"disabled":true}).addClass('disabled');
				};

				$("#" + id + " tbody tr input[name='key']").each(function(){
					if((',' + ids + ',').indexOf(',' + this.value + ',') != -1)
					{
						var list = $('.tr'+this.value);
						if(list.length > 0)
						{
							list.each(function(){
								fun($(this));
							});
						}
						else
						{
							parent = $(this).parent().parent();
							fun(parent);
						}
						this.checked = false;
						
					}
					
					if($("#" + id + " tbody tr:not([disabled])").length == 0)
						location.reload(true);
				});
			}
			else
				$.ajaxError(result.content);
		}
	});
}

function disableShop(obj,id,pk,args)
{
	var ids =  new Array();
	if(isNaN(id))
	{
		$("#" + id + " input:checked[name='key']").each(function(){
			ids.push(this.value);
		});
	}
	else
	{
		ids.push(id);
		var parent = $(obj).parent().parent();
		id = parent.parent().parent().attr('id');
	}
	
	ids = ids.join(',');
	if(ids == '')
		return false;
	
	var query = new Object();
	query.id = ids;
	
	$.ajax({
		url: APP + '?' + VAR_MODULE + '=' + CURR_MODULE + '&' + VAR_ACTION + '=disable',
		type:"POST",
		cache: false,
		data:query,
		dataType:"json",
		success: function(result){
			if(result.isErr == 0)
			{
				var fun = function(parent){
					$('td span,td a',parent).each(function(){
						if (typeof(this.onclick) == 'function' && this.onclick.toString() != '')
						{
							if(this.onclick.toString().indexOf('toggleStatus') != -1)
							{
								var img = $('img',this).get(0);
								img.src = img.src.replace('status','disabled');
							}
							
							this.onclick = '';
						}
					});
					
					parent.attr({"disabled":true,"title":ALREADY_REMOVE});
					$("td",parent).attr({"disabled":true}).addClass('disabled');
					$("td *",parent).attr({"disabled":true}).addClass('disabled');
				};

				$("#" + id + " tbody tr input[name='key']").each(function(){
					if((',' + ids + ',').indexOf(',' + this.value + ',') != -1)
					{
						var list = $('.tr'+this.value);
						if(list.length > 0)
						{
							list.each(function(){
								fun($(this));
							});
						}
						else
						{
							parent = $(this).parent().parent();
							fun(parent);
						}
						this.checked = false;
						
					}
					
					if($("#" + id + " tbody tr:not([disabled])").length == 0)
						location.reload(true);
				});
			}
			else
				$.ajaxError(result.content);
		}
	});
}
</script>
<include file="Public:footer" />